/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.permit.controller.assembler;

import com.google.common.collect.Lists;
import java.util.List;
import java.util.Objects;
import net.siufung.core.utils.CopyUtil;
import org.springframework.util.CollectionUtils;
import net.siufung.market.base.permit.mapper.entity.Permit;
import net.siufung.market.base.permit.controller.model.vo.PermitVo;

/**
 *
 * 系统权限表 持久层展示层组装器
 *
 * @author 陈建峰
 * @since 2022-07-05 22:19:50
 */
public class PermitAssembler {

    /**
     * Permit 转换成 PermitVo
     * @param permit 数据库实体
     * @return PermitVo 视图
     */
    public static PermitVo from(Permit permit){
        if(!Objects.isNull(permit)){
            PermitVo permitVo = new PermitVo();
            CopyUtil.copyProperties(permit, permitVo);
            return permitVo;
        }
        return null;
    }

    /**
     * PermitList 转换成 PermitVoList
     * @param permitList 数据库实体集合
     * @return List<PermitVo> 视图集合
     */
    public static List<PermitVo> fromList(List<Permit> permitList){
        List<PermitVo> permitVoList = Lists.newArrayList();
        if(!CollectionUtils.isEmpty(permitList)){
            PermitVo permitVo;
            for (Permit permit: permitList) {
                permitVo = new PermitVo();
                CopyUtil.copyProperties(permit, permitVo);
                permitVoList.add(permitVo);
            }
        }
        return permitVoList;
    }
}

